package com.project.finance.mobile.packbackorder.service.impl;

import com.project.finance.common.mapper.TbDebitOrderMapper;
import com.project.finance.common.po.TbDebitOrder;
import com.project.finance.common.resultconfig.Result;
import com.project.finance.common.resultconfig.ResultGenerator;
import com.project.finance.mobile.packbackorder.service.PackBackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Slf4j
@Service
public class PackBackServiceImpl implements PackBackService {
    @Autowired
    private TbDebitOrderMapper tbDebitOrderMapper;

    @Override
    public HashMap<Object,Object> findOne(Integer userId) {

        List<TbDebitOrder> tbDebitOrders = tbDebitOrderMapper.findOne(userId);
        log.info("tbDebitOrders*********"+tbDebitOrders);
        //查询剩余几笔贷款待还
        Integer packbackCount=tbDebitOrderMapper.selectNum(userId);
        log.info("packbackCount..........."+userId);
        //查询剩余还款金额
        Integer packbackAmount=tbDebitOrderMapper.selectMoney(userId);
            log.info("packbackAmount-------"+userId);
        HashMap<Object, Object> resultMap = new HashMap<>();
        ArrayList<Object> objects = new ArrayList<>();

        resultMap.put("packbackAmount",packbackAmount);
        resultMap.put("packbackCount",packbackCount);

        for (TbDebitOrder tbDebitOrder : tbDebitOrders) {
            HashMap<Object, Object> map = new HashMap<>();
            map.put("debitOrderId",tbDebitOrder.getDebitOrderId());
            map.put("surplusAmount",tbDebitOrder.getSurplusAmount());
            map.put("debitDate",tbDebitOrder.getDebitDate());
            map.put("debitAmount",tbDebitOrder.getDebitAmount());
            map.put("surplusNumber",tbDebitOrder.getSurplusNumber());
            objects.add(map);
        }
        resultMap.put("paybackList",objects);
        /*Result  result = ResultGenerator.apiSuccess(resultMap);*/
        return resultMap;


    }

}
